import urllib.request

# 1.url
url = "https://www.hao123.com/"

# 2.添加请求头
header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"
}

# 3.构建请求对象
requests = urllib.request.Request(url, headers=header)

# 4.发送请求对象
response = urllib.request.urlopen(url)

# 5.读取数据
data = response.read().decode('utf-8')

#6.写入文件
with open('01cookies.html', mode='w', encoding='utf-8') as f:
    f.write(data)
